﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DataSettings.Providers;
using DataSettings;

namespace APVdP.UserControls
{
    public partial class CadastroEvento : UserControl
    {
        private RegistroCommands regCommands;
        private Evento evento;

        public CadastroEvento()
        {
            InitializeComponent();
            regCommands = new RegistroCommands();

            this.CarregarTiposEvento();
            this.txtAnexarImagemEvento.Text = "C:/teste/ainda/nao/tem/selecionador.png";
        }

        private void CarregarTiposEvento()
        {
            DataTable dt = regCommands.GetTiposEvento();
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    this.cmbTipoEvento.Items.Add(dt.Rows[i][0].ToString());
                }
            }
            this.cmbTipoEvento.SelectedIndex = 0;
        }

        private void btnCadastrarEvento_Click(object sender, EventArgs e)
        {
            //TODO: fazer tratamentos.
            evento = new Evento();
            evento.PacotesEvento = new List<string>();
            evento.PrecosPacotes = new List<double>();
            evento.TelefonesPromotor = new List<string>();

            try
            {
                evento.NomeEvento = this.txtNomeEvento.Text;
                evento.TipoEvento = this.cmbTipoEvento.Text;
                evento.DataEvento = this.dateDataEvento.Text;
                evento.DiretorioImagemEvento = this.txtAnexarImagemEvento.Text;
                if (this.ckbPacoteIndividual.Checked)
                {
                    evento.PacotesEvento.Add(this.ckbPacoteIndividual.Text);
                    evento.PrecosPacotes.Add(double.Parse(this.txtPrecoIndividual.Text));
                }
                if (this.ckbPacoteEspecial.Checked)
                {
                    evento.PacotesEvento.Add(this.ckbPacoteEspecial.Text);
                    evento.PrecosPacotes.Add(double.Parse(this.txtPrecoEspecial.Text));
                }
                if (this.ckbPacoteFamilia.Checked)
                {
                    evento.PacotesEvento.Add(this.ckbPacoteFamilia.Text);
                    evento.PrecosPacotes.Add(double.Parse(this.txtPrecoFamilia.Text));
                }
                evento.NomePromotor = this.txtNomePromotor.Text;
                string[] telefonesPromotores = this.txtTelefonePromotor.Text.Trim().Split(';');
                foreach (string telefone in telefonesPromotores)
                {
                    evento.TelefonesPromotor.Add(telefone);
                }
            }
            catch (Exception ex)
            {
                ;
            }
            finally
            {
                regCommands.CadastrarEvento(evento);

                this.SetLimparCamposCadastro();
                MessageBox.Show("Evento Cadastrado Com Sucesso!");
            }
        }

        private void SetLimparCamposCadastro()
        {
            this.txtNomeEvento.Text = string.Empty;
            this.cmbTipoEvento.SelectedIndex = 0;
            this.dateDataEvento.Value = DateTime.Now;
            this.txtAnexarImagemEvento.Text = "C:/teste/ainda/nao/tem/selecionador.png";
            this.ckbPacoteIndividual.Checked = false;
            this.txtPrecoIndividual.Text = string.Empty;
            this.ckbPacoteEspecial.Checked = false;
            this.txtPrecoEspecial.Text = string.Empty;
            this.ckbPacoteFamilia.Checked = false;
            this.txtPrecoFamilia.Text = string.Empty;
            this.txtNomePromotor.Text = string.Empty;
            this.txtTelefonePromotor.Text = string.Empty;
        }
    }
}
